package com.wang.demo06;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author 19225
 * @create 2021/1/14 22:56
 */
public class UserInvocationHandler implements InvocationHandler {

    private User user;

    public void setUser(User user) {
        this.user = user;
    }

    //生成得到代理类
    public Object getProxy()
    {
        return Proxy.newProxyInstance(
                this.getClass().getClassLoader(),
                user.getClass().getInterfaces(),
                this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object invoke = method.invoke(user, args);
        return invoke;
    }
}
